<template>
  <el-dialog
    title="请选筛选数据"
    :visible.sync="dialogVisible"
    width="370px">
    <div v-if="actType!=='SignList'">
      操作类型:
      <el-select v-model="actType">
        <el-option :value="item.id" v-for="(item,index) in actTypeArr" :key="index" :label="item.name"></el-option>
      </el-select>
    </div>
    <div style="margin-top: 10px;">
      时间段:
      <el-date-picker
        style="width: 41%;"
        v-model="startTime"
        value-format="yyyy-MM-dd"
        type="date"
      placeholder="开始时间">
      </el-date-picker>

      <el-date-picker
        style="width: 41%;"
        v-model="endTime"
        value-format="yyyy-MM-dd"
        type="date"
        placeholder="结束时间">
      </el-date-picker>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="confirm">确认选择</el-button>
    </div>
  </el-dialog>

</template>

<script>
export default {
  name: 'ChooseLogFormDialog',
  data: function () {
    return {
      actTypeArr:[
        {name:'全部',id:''}
      ],
      callback:null,
      dialogVisible:false,
      startTime:'',
      endTime:'',
      actType:'',
    }
  },
  mounted () {
    let $this = this
    $this.bus.$on('BackKeyCallBus',function (){
      $this.dialogVisible=false
      $this.$forceUpdate()
    })
    $this.bus.$on('ChooseLogFormDialogCallBus', function (callback,actType,dateTime,actTypeArr) {
      $this.actTypeArr=Object.assign([{name:'全部',id:''}],actTypeArr)
      $this.callback=callback
      if (dateTime){
        var split = dateTime.split(',')
        $this.startTime=split[0]
        $this.endTime=split[1]
      }
      if (!actType){
        $this.actType=''
      }
      $this.actType=actType
      $this.dialogVisible = true
      $this.$forceUpdate()
    })

  },
  methods: {
    confirm:function () {
      if (typeof this.callback==='function'){
        var time=''
        if (this.startTime || this.endTime){
          time=this.startTime+','+this.endTime
        }
        if (this.actType==='SignList'){
          this.callback(time)
        }else{
          this.callback(this.actType,time)
        }
        this.dialogVisible = false
      }
    }
  }
}
</script>

<style scoped>

</style>
